//
// Copyright (c) 2009-2011, chunquedong
//
// This file is part of ChunMap project
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
//
// History:
//   2011-09-30  Jed Young  Creation
//

using gfx
using gfx2

using chunmapModel
using chunmapData
using chunmapRaster

**
** simple draw point
**
@Js
const class SimplePointSym : GeometrySym
{
  const Pen pen := Pen.defVal
  const Brush brush := Color.red
  const Brush strokeBrush := Color.black

  const Int style := 0
  const static Int styleCircle := 0
  const static Int styleSquare := 1

  const Int size := 7

  const Bool fill := true
  const Bool stroke := false

  new make(|This| f) { f(this) }

  override Void drawGeometry(Geometry geom, RenderEnv r)
  {
    if (geom isnot GeoPoint) return
    GeoPoint p := geom

    half := size / 2f
    x := r.view.x2Screen(p.x) - half
    y := r.view.y2Screen(p.y) - half

    g := r.g

    if (style == styleCircle)
    {
      if (fill)
      {
        if (g.brush != brush) g.brush = brush
        g.fillOval(x.toInt, y.toInt, size, size)
      }

      if (stroke)
      {
        if (g.brush != strokeBrush) g.brush = strokeBrush
        if (g.pen != pen) g.pen = pen
        g.drawOval(x.toInt, y.toInt, size, size)
      }
    }
    else if (style == styleSquare)
    {
      if (fill)
      {
        if (g.brush != brush) g.brush = brush
        g.fillRect(x.toInt, y.toInt, size, size)
      }

      if (stroke)
      {
        if (g.brush != strokeBrush) g.brush = strokeBrush
        if (g.pen != pen) g.pen = pen
        g.drawRect(x.toInt, y.toInt, size, size)
      }
    }
  }
}